﻿namespace VividKit.PresentationModel.Navigation
{
    using System;
    using System.Windows.Navigation;

    /// <summary>
    /// Provides default implementation for the <see cref="INavigationService"/> interface.
    /// </summary>
    internal class DesktopNavigationService : INavigationService
    {
        private readonly NavigationService navigationService;

        /// <summary>
        /// Initializes a new instance of the <see cref="DesktopNavigationService"/> class.
        /// </summary>
        /// <param name="navigationService">The navigation service.</param>
        public DesktopNavigationService(NavigationService navigationService)
        {
            this.navigationService = navigationService;
        }

        /// <summary>
        /// Gets a value that indicates whether there is at least one entry in back navigation history.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if there is at least one entry in back navigation history; otherwise, <c>false</c>.
        /// </value>
        public bool CanGoBack
        {
            get
            {
                return this.navigationService.CanGoBack;
            }
        }

        /// <summary>
        /// Navigates to the most recent entry in back navigation history, if there is one.
        /// </summary>
        public void GoBack()
        {
            this.navigationService.GoBack();
        }

        /// <summary>
        /// Navigates to a view associated with the specified <see cref="T:NavigatorViewModel">context</see>.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="targetType">The target type.</param>
        /// <param name="target">The target view name.</param>
        /// <param name="extraData">An optional user-defined data object passed to the target.</param>
        public void Navigate(INavigable source, Type targetType, string target, object extraData)
        {
            var navigator = new DesktopNavigator(this.navigationService, source, targetType, target, extraData);
            navigator.Navigate();
        }

        /// <summary>
        /// Remove the most recent entry from the back stack.
        /// </summary>
        public void RemoveBackEntry()
        {
            this.navigationService.RemoveBackEntry();
        }
    }
}